<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
</head>
<body>

<form class="layui-form" lay-filter="layui-form">
    <div class="mainBox">
        <div class="main-container">
            <div class="main-container">
                <div class="layui-form-item" style="width: 40%">
                    <label class="layui-form-label"><text title="必填项" style="color:red;">*</text>作者昵称</label>
                    <div class="layui-input-block">
                        <input type="text"   name="author_name" lay-verify="required|len" autocomplete="off" placeholder="请输入作者昵称" class="layui-input author_input">
                    </div>
                </div>
                <div class="layui-form-item" style="width: 40%">
                    <label class="layui-form-label"><text title="必填项" style="color:red;">*</text>作者身份</label>
                    <div class="layui-input-block">
                        <input type="text"  name="role_type" lay-verify="required|len" autocomplete="off" placeholder="请输入作者身份" class="layui-input author_input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">身份标识图片</label>
                    <div class="layui-input-block">
                        <div class="laytpUpload"
                             data-name="icon"
                             data-accept="image"
                             data-type="ali-oss"
                             data-showChoiceBtn="false"
                        ></div>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label">头像</label>
                    <div class="layui-input-block">
                        <div class="laytpUpload"
                             data-name="author_head"
                             data-accept="image"
                             data-type="ali-oss"
                             data-showChoiceBtn="false"
                        ></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="laytp-btn laytp-btn-primary laytp-btn-sm" lay-submit="" lay-filter="add">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="laytp-btn laytp-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>
<script>
    if(localStorage.getItem("staticDomain")){
        document.write("<link rel='stylesheet' href='" + localStorage.getItem("staticDomain") + "/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='" + localStorage.getItem("staticDomain") + "/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }else{
        document.write("<link rel='stylesheet' href='/static/component/layui/css/layui.css?v=" + localStorage.getItem("version") + "'>");
        document.write("<script src='/static/component/layui/layui.js?v="+localStorage.getItem("version")+"'><\/script>");
        document.write("<script src='/static/component/laytp/layuiConfig.js?v="+localStorage.getItem("version")+"'><\/script>");
    }
</script>
<script>
    layui.use(['laytp'],function(){
        $('.author_input').blur(function(){
            var value = this.value;
            var node = this;
            if(value.length > 4){
                layer.tips('最大长度为四个字节',this,{
                    tips:[3,'red']
                });
                node.focus();
            }
        })

        layui.form.verify({
            len:function(value,item){
                if(value.length > 4){
                    return '最大长度为四个字符';
                }
            }
        })
        layui.form.on('submit(add)', function(data){
            var btnAnim = layui.button.load({elem:$(this)});
            facade.ajax({
                route:'/admin.dawn.author/add',
                data : data.field
            }).done(function(res){
                if(res.code === 0){
                    parent.layui.layer.close(parent.layui.layer.getFrameIndex(window.name));//关闭当前页
                    parent.layui.table.reload("laytp-table");
                }
                btnAnim.stop();
            }).fail(function(){
                btnAnim.stop();
            });
            return false;
        });
    })
</script>
</body>
</html>
